<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
  	<title>会员登录</title>
  	<script language="javascript" src="js/jquery.js"></script>
  	<script language="javascript" src="js/tinybox.js"></script>
  </head>
  
  <body>
  	<div style="text-align:center;">
	  	<div style="border-style: solid;width:500px; border-width: 1px; border-color: red;">
	  		<h1>用户登录</h1>
	       <form action="">
	       		<table>
	       			<tr>
	       				<td>用户名：</td>
	       				<td><input type="text" name="userName" id="userName" size="19"/></td>
	       			</tr>
	       			<tr>
	       				<td>密&nbsp;&nbsp;码：</td>
	       				<td><input type="password" name="userPwd" id="userPwd" size="19" onkeydown="keylogin(event);"/></td>
	       			</tr>
	       			<tr>
	       				<td colspan="2" style="text-align: center;"> 
	       					<input type="button" value="登录"  onclick="logins();" style="width: 100px;height:30px;"/>
	       					&nbsp;&nbsp;&nbsp;<a href="register.jsp">商家注册</a>
	       				</td>
	       			</tr>
	       			
	       		</table>
	       </form>
	      </div>
      </div>
     <script type="text/javascript"> 
     		document.getElementById("userName").focus();
     		function logins() {
				var userName = $("#userName").val();
     			var userPwd = $("#userPwd").val();
     			
				if (userName == "") { 
					alert("请输入会员名！");
					document.getElementById("userName").focus();
				} else if (userPwd == "") {
					alert("请输入密码！");
					document.getElementById("userPwd").focus();
					//url : "user/login!loginUser.html",
				} else { 
							$.ajax( {
								type : "post",
								url : "user/login!restaurentUserLogin.html",
								data : {
									userName : userName,
									userPwd : userPwd
								},
								success : function(result) { 
									
									if (result == 0) {
										window.location.href = "main!index.html?"+new Date(); //admin/entry/member-main.action?id="+result.membername;
									} else if (result == -1) {
										alert("用户名输入错误");
										document.getElementById("userName").focus();
									} else if (result == -2) {
										alert("密码输入错误！");
										document.getElementById("userPwd").focus();
									} else if (result == -3) {
										alert("您的账号审核中，请稍候登录...");
									} else if (result == -4) {
										alert("您的账号审核不通过");
									} else if (result == -5) {
										alert("您的账号已锁定不能登录");
									} else if (result == -6) {
										alert("您的账号已作废不能登录");
									}
								},
								error : function(result) {
									alert("数据读取失败！");
								}
							});
				}
			}
     		
     		//回车直接登录
     		function keylogin(event){
     			var event=window.event?window.event:event;
     			
     			if(event.keyCode==13){
     				logins();
     			}
     		}
     </script>
  </body>
</html>
